package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.Button;
import android.widget.LinearLayout;

public class UC1Activity extends AppCompatActivity {

    private Button btnHorizontal, btnVertical, btnLeft, btnBack;
    private LinearLayout mainLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc1);

        // 初始化按钮
        btnHorizontal = findViewById(R.id.btnHorizontal);
        btnVertical = findViewById(R.id.btnVertical);
        btnLeft = findViewById(R.id.btnLeft);
        btnBack = findViewById(R.id.btnBack);

        // 获取包含三个按钮的容器布局
        mainLayout = findViewById(R.id.mainLayout);

        // 设置按钮点击事件
        btnHorizontal.setOnClickListener(v -> {
            mainLayout.setOrientation(LinearLayout.HORIZONTAL);
        });

        btnVertical.setOnClickListener(v -> {
            mainLayout.setOrientation(LinearLayout.VERTICAL);
        });

        btnLeft.setOnClickListener(v -> {
            mainLayout.setGravity(Gravity.LEFT);
        });

        btnBack.setOnClickListener(v -> {
            Intent intent = new Intent(UC1Activity.this, MainActivity.class);
            startActivity(intent);
        });
    }
}